<?php
class Mcategory extends CI_Model{
    
    public function __construct(){
        parent::__construct();
        $this->load->database();
    }

    public function getCategoryAll(){
        $this->db->select(' id, name, uname, display, page_title, page_keyword, page_description, type');
        $this->db->from('category');
        $query = $this->db->get();
        return $query->result_array();
    }
    
    public function getCategory($number, $offset){
        $this->db->select(' id, name, uname, display, page_title, page_keyword, page_description, type');
        $this->db->from('category');
        $this->db->limit($number, $offset);
        $query = $this->db->get();
        return $query->result_array();
    }

    public function insertCategory($param){
        $data = array(
            'id' => NULL,
            'name' => $param['name'],
            'uname' => $param['uname'],
            'display' => 'Y',
            'page_title' => $param['page_title'],
            'page_keyword' => $param['page_keyword'],
            'page_description' => $param['page_description'],
            'type' => $param['type']
        );
        $this->db->insert('category', $data);
    }

    public function updateCategory($param){
        $data = array(
            'name' => $param['name'],
            'uname' => $param['uname'],
            'display' => $param['display'],
            'page_title' => $param['page_title'],
            'page_keyword' => $param['page_keyword'],
            'page_description' => $param['page_description'],
            'type' => $param['type']
        );
        $this->db->where('id', $param['id']);
        $this->db->update('category', $data);
    }

    public function deteleCategory($id){
        $this->db->where('id', $id);
        $this->db->delete('category');
    }

    public function getCategoryByUname($category_uname){
        $this->db->select(' id, name, uname, display, page_title, page_keyword, page_description, type');
        $this->db->from('category');
        $this->db->where("uname", $category_uname);
        $query = $this->db->get();
        return $query->row_array();
    }

    public function countCategory(){
        $this->db->select('count(id) as total');
        $this->db->from('category');       
        $query = $this->db->get();
        return $query->row('total');
    }
}
?>